package com.jwsoft.manager.core.integration.eduAddressTree;

import com.jwsoft.manager.common.vo.eduAddressTree.EduAddressTreeVO;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 地址树变更辅助类
 *
 * @author fangs
 */
public class TreeChangeHelper {
    private static final ThreadLocal<List<EduAddressTreeVO>> TREE_CHANGE = new ThreadLocal<>();

    public static void addTreeChange(EduAddressTreeVO addressTreeVO) {
        List<EduAddressTreeVO> addressTreeVOList = TREE_CHANGE.get();
        if (CollectionUtils.isEmpty(addressTreeVOList)) {
            addressTreeVOList = new ArrayList<>();
        }
        addressTreeVOList.add(addressTreeVO);
        TREE_CHANGE.set(addressTreeVOList);
    }

    public static void addTreeChange(List<EduAddressTreeVO> changeList) {
        List<EduAddressTreeVO> addressTreeVOList = getTreeChange();
        addressTreeVOList.addAll(changeList);
        TREE_CHANGE.set(addressTreeVOList);
    }

    public static List<EduAddressTreeVO> getTreeChange() {
        List<EduAddressTreeVO> addressTreeVOList = TREE_CHANGE.get();
        if (CollectionUtils.isEmpty(addressTreeVOList)) {
            addressTreeVOList = new ArrayList<>();
        }
        return addressTreeVOList;
    }

    public static void clear() {
        TREE_CHANGE.remove();
    }
}
